package com.noble.meether.notify.act;

import android.os.Bundle;
import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.noble.meether.R;
import com.noble.glamour.module.util.BaseUtil;
import com.noble.library.base.BaseAppCompatActivity;

/**
 * 应用非锁屏状态下消息弹框
 */
public class UserMailNotifyAct extends BaseAppCompatActivity implements View.OnClickListener {

    private ImageView user_img;
    private TextView user_name, user_content;

    private String content;//消息内容
    private int iClick;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.common_user_mail_notify);

        initData();
        initView();
        setData();
    }

    private void initData() {
        content = getIntent().getStringExtra("content");
    }

    private void initView() {
        user_img = findViewById(R.id.user_img);
        user_name = findViewById(R.id.user_name);
        user_content = findViewById(R.id.user_content);

        findViewById(R.id.user_mail_notify_main).setOnClickListener(this);
        findViewById(R.id.floating_tip).setOnClickListener(this);
        findViewById(R.id.btn_ignore).setOnClickListener(this);
        findViewById(R.id.btn_reply).setOnClickListener(this);
    }

    private void setData() {
//        if (simpleData == null || TextUtils.isEmpty(content)) {
//            finish();
//        } else {
//            if (TextUtils.isEmpty(simpleData.getAvatar())) {
//                user_img.setImageResource(R.drawable.ic_launcher);
//            } else {
//                ImageLoader.loadAvatar(this, simpleData.getAvatar(), user_img);
//            }
//            user_name.setText(TextUtils.isEmpty(simpleData.getNickname()) ? String.valueOf(simpleData.getUid()) :
//                    simpleData.getNickname());
//            ll_age.setBackgroundResource(simpleData.getGender() == 1 ?
//                    R.drawable.bg_shape_round_blue : R.drawable.bg_shape_round_pink_2);
//            iv_sex.setImageResource(simpleData.getGender() == 1 ?
//                    R.drawable.f1_sex_male_2 : R.drawable.f1_sex_female_2);
//            tv_age.setText(simpleData.getAge() + App.context.getString(R.string.age));
//            tv_height.setText(simpleData.getHeight() + "cm");
//            user_content.setText(Html.fromHtml(content));
//
//            HideMainMessageForThreeSec();
//        }
    }

    public void HideMainMessageForThreeSec() {
        new Handler().postDelayed(this::finish, 5000);
    }

    @Override
    protected void onResume() {
        super.onResume();
        overridePendingTransition(R.anim.top_in, 0);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(0, R.anim.top_out);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (BaseUtil.isOutOfBounds(this, event)) {
            if (event.getAction() == MotionEvent.ACTION_DOWN ||
                    event.getAction() == MotionEvent.ACTION_UP ||
                    event.getAction() == MotionEvent.ACTION_MOVE) {
                finish();
                return true;
            }
        }
        return super.onTouchEvent(event);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.user_mail_notify_main:
                if (iClick < 1) {
                    iClick++;
                    return;
                }
                finish();
                break;
            case R.id.btn_ignore:
                finish();
                break;
            case R.id.floating_tip:
            case R.id.btn_reply:
//                finish();
//                if (simpleData == null || simpleData.getUid() == 0) return;
//
//                UIShow.showMainWithBackMessage(this);
//                Invoker.getInstance().doInApp(null, "cmd_open_chat", "{\"uid\":" + simpleData.getUid() + "}");
                break;
        }
    }
}
